package com.manor.main.adapter

import android.graphics.Color
import android.view.View
import android.widget.ImageView
import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.lxj.xpopup.XPopup
import com.manor.common.CommonAppConfig
import com.manor.common.http.HttpCallback
import com.manor.common.utils.ToastUtil
import com.manor.main.R
import com.manor.main.bean.WithdrawalAccountBean
import com.manor.main.http.MainHttpUtil

class WithdrawalAccountAdapter(layoutResId: Int, data: List<WithdrawalAccountBean>?, var id:String,internal  val listener: IAddListListener) :
        BaseQuickAdapter<WithdrawalAccountBean, BaseViewHolder>(layoutResId, data as MutableList<WithdrawalAccountBean>?) {

    interface IAddListListener {//创建抽象类

        fun deleteBank()

    }
    override fun onBindViewHolder(helper: BaseViewHolder, position: Int) {
        super.onBindViewHolder(helper, position)
        val tv_name = helper.getView<TextView>(R.id.tv_name)
        val tv_sone = helper.getView<TextView>(R.id.tv_sone)
        val tv = helper.getView<TextView>(R.id.tv)
        var item =   data[position]
        if(item.id.equals(id)){
            tv_name.setTextColor(Color.parseColor("#ffffff"))
            tv_sone.setTextColor(Color.parseColor("#ffffff"))
            tv.visibility = View.VISIBLE
        }else{
            tv_name.setTextColor(Color.parseColor("#80ffffff"))
            tv_sone.setTextColor(Color.parseColor("#80ffffff"))
            tv.visibility = View.INVISIBLE
        }

        val im_pic = helper.getView<ImageView>(R.id.im_pic)

        val tv_context = helper.getView<TextView>(R.id.tv_context)
        val tv_type = helper.getView<TextView>(R.id.tv_type)
        if (item.id == "") {

            im_pic.visibility = View.GONE
            tv_name.text = ""
            tv_sone.text = ""
            tv_type.text = "添加"
        } else {
            tv_name.text = item.account + ""
            tv_sone.text = item.name + ""
          tv_type.text = "删除"
        }
        tv_type.setOnClickListener {

            XPopup.Builder(context)
                    .asConfirm(null, "是否确认删除此账户") {
                        MainHttpUtil.getDelUserAccount(CommonAppConfig.getInstance().uid, CommonAppConfig.getInstance().token,
                                item.id + "", object : HttpCallback() {
                            override fun onSuccess(code: Int, msg: String, info:String) {
                                if (code == 0) {
                                    listener.deleteBank()

                                } else {
                                    ToastUtil.show(msg)
                                }
                            }
                        })
                    }
                    .show()
        }
    }

    override fun convert(helper: BaseViewHolder, item: WithdrawalAccountBean) {


    }


}